package com.admin.action;

import com.admin.bean.PayApp;
import com.admin.service.PayAppAdminService;
import com.data.util.CheckDataUtils;
import com.data.util.FinalStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 付费推荐的APP管理
 *
 * @author:HingLo
 * @create 2017-09-27 11:36
 **/
@Controller
@RequestMapping("/payAppAdmin/admin/")
public class PayAppAdminAction {
    @Autowired
    private PayAppAdminService payAppAdminService;

    @GetMapping("inputPayApp")
    public String inputPayAppAdminAction(HttpServletRequest request) {
        List<?> list = payAppAdminService.findAllPayAppAdminService();
        request.setAttribute("dataMap", list);
        return "/WEB-INF/admin/banner/payApp";
    }


    /**
     * 进入到添加付费软件的图界面
     *
     * @return
     */
    @GetMapping("addPayApp")
    public String inputPayAppAddAdminAction() {
        return "/WEB-INF/admin/banner/addPayApp";
    }


    /**
     * 添加软件类型
     *
     * @param request
     * @return
     */
    @PostMapping("submitPayApp")
    public String submitPayAppAdminAction(PayApp payApp, String stime, String etime, HttpServletRequest request) {
        boolean bool = false;
        if (payApp != null && CheckDataUtils.stringUtils(stime, etime)) {
            int type = payApp.getType();
            if (type == FinalStringUtils.GOODSOFTWARE || type == FinalStringUtils.PAYSOFTWARE) {
                bool = payAppAdminService.submitPayAppAdminService(payApp, stime, etime);
            }
        }
        request.setAttribute("bool", bool);
        return "/WEB-INF/admin/banner/addPayApp";
    }

    /**
     * 删除软件类型
     *
     * @return
     */
    @PostMapping("delPayApp")
    @ResponseBody
    public String delPayAppAdminAction(String id) {
        boolean bool = false;
        if (CheckDataUtils.stringUtilsID(id)) {
            bool = payAppAdminService.delpayAppAdminService(id);
        }
        return String.valueOf(bool);
    }
}
